home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / MacMemory.h < prev    next >
Text File  |  1995-07-27  |  2KB  |  44 lines

  1. /*
  2. MacMemory.h
  3.  
  4. Redefines all the Standard C memory allocation functions to be implemented
  5. directly as calls to the Macintosh Memory Manager.
  6.  
  7. You use MacMemory.h by adding the line
  8. #include "MacMemory.h"
  9. either to your THINK/CodeWarrior C project prefix or to some header file that 
  10. you include in all your files.
  11.  
  12. Symantec is rather apologetic about the poor performance of their memory
  13. manager, which implements the Standard C library functions free, malloc, calloc,
  14. and realloc (THINK Reference:Standard Libraries:"Allocating Memory"). The THINK
  15. C memory manager requests 15 KB (or larger) chunks of memory from Apple's memory
  16. manager and then doles out this memory to your program in whatever size pieces
  17. you request. The problem is that the THINK C memory manager isn't smart enough
  18. to recombine pieces you return to it via free, so programs (like Quest)
  19. that do a lot of allocation and freeing end up triggering the THINK C memory
  20. manager to keep asking for new 15KB chunks that eventually use up all free
  21. memory until the program fails for lack of memory. Spuriously eating up free 
  22. memory is called a "memory leak".
  23.  
  24. The benefit of using MacMemory.h is that you will use memory efficiently.
  25. The disadvantage is that it is possible (I haven't checked) that the THINK C
  26. memory manager is much quicker for a series of small allocations. The Apple
  27. Memory Manager is quite slow. E.g. calls to NewGWorld take 0.2 s on a Mac II,
  28. and my impression is that most of this time is taken up allocating memory.
  29.  
  30. HISTORY:
  31. 3/5/94 dgp wrote it.
  32. 11/15/94 dgp #include <stdlib.h> so that THINK C will read in the definition of size_t.
  33. */
  34. #pragma once    // Only include this once.
  35.  
  36. #ifndef _STDLIB
  37.     #include <stdlib.h>    // size_t
  38. #endif
  39. void *MacRealloc(void *oldPtr,size_t size);
  40. #define free(ptr) DisposePtr((Ptr)(ptr))
  41. #define malloc(bytes) (void *)NewPtr(bytes)
  42. #define calloc(n,size) (void *)NewPtrClear((size_t)(n)*(size))
  43. #define realloc(ptr,size) MacRealloc(ptr,size)
  44.